<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String input = request.getParameter("srchterm");
	session.setAttribute("srchterm", input);
%>
<script type="text/javascript">
function getUrlParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}
</script>
<t:wrapper title="Video list">
<script>
var srchterm = getUrlParameter('srchterm');
$(".page-header h1").html("Search results for keyword "+ srchterm);
$.ajax({
    url: "/Signport/search",
    type: 'GET',
    data: {srchterm: srchterm},
    success: function(data) {
    	console.log(data);
    	$("#resultSet").empty();
		$.each(data, function(index, element){
			console.log(element);
			console.log(element.video.videoName);
			console.log(element.video.videoTag);
			console.log(element.video.videoUrl);
			
			var newNode = $("<div class='profile-activity clearfix'>")
								.append($("<p><a href='videopage.jsp?v="+element.video.videoUrl+"'>"+element.video.videoName+"</a></p>"))
								.append($("<p>"+element.video.videoTag+"</p>"));
			$("#resultSet").append(newNode);
			
		})
    },
    error: function(textStatus, errorThrown) {
    	alert("error");
    	console.log("search error");
    	console.log(textStatus);
    	console.log(errorThrown);
    }
});
</script>
		<div class="page-header">
	<div class="page-content">
			<h1>Search results</h1>
		</div>
		<div class="row">
			<div class="col-xs-6">
				<div id="resultSet">
					
				</div>
			</div>
		</div>
	</div>
</t:wrapper>
